



public class EqualityExpr extends ConditionalAndExpr {

	AdditiveExpr addExpr;
	EqualityExpr eqExpr;
	int op;


	public EqualityExpr() {

	}

	public EqualityExpr(AdditiveExpr addExpr, EqualityExpr eqExpr, int op) {
		super();
		this.addExpr = addExpr;
		this.eqExpr = eqExpr;
		this.op = op;
	}

	public void check() throws SemanticException {
		addExpr.check();
		if (eqExpr != null)
			eqExpr.check();
		checkType();
	}

	public int checkType() throws SemanticException {
		if (eqExpr != null) {
			if (eqExpr.checkType() != addExpr.checkType()) {
				System.out.println(eqExpr + " , " + addExpr);
				throw new SemanticException(
						"Equality expression must take boolean types");
			}
			return Type.BL;

		}

		return addExpr.checkType();

	}

	public String toString() {
		String ret = "EqualityExpression\n";
		String s = "";
		if (eqExpr != null)
			s += eqExpr.toString() + (op == Type.EQ ? "==" : "!=") + "\n";
		s += addExpr.toString();
		for (String st : s.split("\n"))
			ret += "| " + st + "\n";
		return ret;
	}
}
